package GUI;

/**
 * Show student data in a table for the Student type user
 */

import java.awt.Dimension;
import java.awt.GridLayout;
//import java.nio.file.Path;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JButton;

import DBconnection.mysqlConnection;



public class ShowDataScreen extends JPanel {
   
	
	
	
    private JLabel lblViewAcademicData = null;
	private JButton btnBack = null;
	private Dimension defaultDim=null;
	private JScrollPane scrollPane=null;
	public String[][]data = null;
	public mysqlConnection con=null;						//for getting the evo file
	private  JTable dataTable_1=null;
	private String IsExceptional = "Exceptional request approved";
 
    public ShowDataScreen(StudentMainMenu stmn) {
    	
        super(new GridLayout(1,0));
 
        String[] columnNamesStr = {"Year","Semester","Course", "Grade","Comments", "Evaluation form"};
        data = new String[stmn.user.StudentData.ListOfCourses.lOfCourses.size()][6];
    	
    	///////////////////////////
        //geting evo file
       String userID= stmn.myLoginFrame.userID;
       String getCoures =stmn.user.getCourse();
       String [] cid = getCoures.split(" ");
       
       
     //  System.out.println("getEvaluationForm "+userID+" "+cid[1]);
       stmn.myLoginFrame.client.handleMessageFromClientUI("getEvaluationForm "+userID+" "+cid[1]);
 
        /////////////////////
        
        for(int i=0, j=0,count=0;i<stmn.user.StudentData.ListOfCourses.lOfCourses.size();i++)
    	{
    	if((stmn.user.getYear().equals((stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getYear().toString())))&&
    		(stmn.user.getSem().equals(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getSemester().toString())&&
    		(stmn.user.getCourse().endsWith(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getCid().toString()))))
    			
    	{
    		 data[count][j]=stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getYear().toString() ;
    		 data[count][j+1]=stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getSemester().toString();
    		 data[count][j+2]=stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getCname().toString()+" "+  stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getCid().toString();
    		 data[count][j+3]=stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getGrade().toString();
    		 if(!stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getIsExeptional()) IsExceptional=" ";
    		 data[count][j+4]=IsExceptional;// a cell for a link to the evaluation file
    		 data[count][j+5]="balbalot";// a cell for a link to the evaluation file
    		 count++;
    	}	
    	 System.out.println(stmn.user.StudentData.ListOfCourses.lOfCourses.size());
    	 System.out.println(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getCid().toString());
    	
    	 System.out.println(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getCname().toString());
    	 System.out.println(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getGrade().toString());
    	 System.out.println(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getYear().toString());
    	 System.out.println(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getSemester().toString());
    	 System.out.println(stmn.user.StudentData.ListOfCourses.lOfCourses.get(i).getIsExeptional().toString());
    	 
    	
    	}
 
         
        final JTable table = new JTable(data, columnNamesStr);
        table.setPreferredScrollableViewportSize(new Dimension(500, 500));
        table.setFillsViewportHeight(true);
        printDebugData(table);
      
        
      
 
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
 
        //Add the scroll pane to this panel.
        add(scrollPane);
        
    }
 
//    public void showNewLink(){
//    	Path newLink = ...;
//    	Path existingFile = ...;
//    	try {
//    	    Files.createLink(newLink, existingFile);
//    	} catch (IOException x) {
//    	    System.err.println(x);
//    	} catch (UnsupportedOperationException x) {
//    	    // Some file systems do not
//    	    // support adding an existing
//    	    // file to a directory.
//    	    System.err.println(x);
//    	}
//    }
    private void printDebugData(JTable table) {
        int numRows = table.getRowCount();
        int numCols = table.getColumnCount();
        javax.swing.table.TableModel model = table.getModel();
 
        System.out.println("Value of data: ");
        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + model.getValueAt(i, j));
            }
            System.out.println();
        }
        System.out.println("--------------------------");
    }
 
   
}




